package com.ika.client;

import java.util.HashMap;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.ika.client.widgets.titlebar.TitleBarWidget;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Ika_Ika implements EntryPoint {
	/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */
	private static final String SERVER_ERROR = "An error occurred while "
			+ "attempting to contact the server. Please check your network "
			+ "connection and try again.";

	/**
	 * Create a remote service proxy to talk to the server-side Greeting service.
	 */
	private final VideoServiceAsync greetingService = GWT
			.create(VideoService.class);



	  private VerticalPanel mainPanel = new VerticalPanel();
	  private TitleBarWidget titleBarWidget=new TitleBarWidget();

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		mainPanel.add(titleBarWidget);
		
		RootPanel.get("root").add(mainPanel);
		
		HistoryManager.clearParameter();
		HistoryManager.putTitle(HistoryManager.INDEX);
		
		History.addValueChangeHandler(new ValueChangeHandler<String>() {

			@Override
			public void onValueChange(ValueChangeEvent<String> event) {
				
				HashMap<String, String> changeValuesMap = new HashMap<String, String>();

				String[] changeValues = event.getValue().substring(1).split(HistoryManager.SYMBOL_SEPARATOR);
				for (String changeItem : changeValues) {
					changeValuesMap.put(changeItem.split(HistoryManager.SYMBOL_ASSIGNMENT)[0], changeItem
					    .split(HistoryManager.SYMBOL_ASSIGNMENT)[1]);
				}
				System.out.println("changeValuesMap=" + changeValuesMap);
				
				if(changeValues.length==1)
				{
					if(changeValuesMap.get(HistoryManager.TITLE) != null)
						{
						String titleValue=changeValuesMap.get(HistoryManager.TITLE);
					
						if(titleValue.equals(HistoryManager.ANIME))	
						{
							titleBarWidget.playVideo();
						}
						if(titleValue.equals(HistoryManager.INDEX))	
						{
							titleBarWidget.playVideo();
						}
						
						};
						
				}
			}
	
		    });
		
	}
	
	 

}
